<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
  <head>
	<meta charset="utf-8">
    <title>line chart</title>
	<script src="../js/d3.v3.min.js"></script>

  <link rel="stylesheet" href="../line/css/d3.line.css" type="text/css"></link>
 
<style>
#chartPanel {
	float: left;
}
#controlPanel {
	position: absolute;
	right: 10px;
	top: 10px;
	width: 260px;
}
.legend {
	font-size: 20px;
}
</style>
  <s:head/>
  </head>

  <body>
  
  <div id="chartPanel"></div>
  <div id="controlPanel">
  	
  	<form action="<s:url action="fileUpload" namespace="/line"/>" method="post" enctype="multipart/form-data">
  		<input type="hidden" name="destPage" value="<%= request.getServletPath()%>" />
  		<div>
  			<label for="dataFile">csv file</label>
  			<s:file name="data" />
  		</div>
  		<div>
  			<input type="submit"/>
  		</div>
  	</form>
  </div>
  
<script>

var margin = {top: 20, right: 20, bottom: 30, left: 50},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var parseDate = d3.time.format("%d-%b-%y").parse;

var x = d3.time.scale()
    .range([0, width]);

var y = d3.scale.linear()
    .range([height, 0]);

var xAxis = d3.svg.axis()
    .scale(x)
    .orient("bottom");

var yAxis = d3.svg.axis()
    .scale(y)
    .orient("left");

var line = d3.svg.line()
    .x(function(d) { return x(d.date); })
    .y(function(d) { return y(d.close); });

var svg = d3.select("body").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

d3.tsv('<s:property value="#session['CURRENT_FILE']"/>', function(error, data) {
  data.forEach(function(d) {
    d.date = parseDate(d.date);
    d.close = +d.close;
  });

  x.domain(d3.extent(data, function(d) { return d.date; }));
  y.domain(d3.extent(data, function(d) { return d.close; }));

  svg.append("g")
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")
      .call(xAxis);

  svg.append("g")
      .attr("class", "y axis")
      .call(yAxis)
    .append("text")
      .attr("transform", "rotate(-90)")
      .attr("y", 6)
      .attr("dy", ".71em")
      .style("text-anchor", "end")
      .text("Price ($)");

  svg.append("path")
      .datum(data)
      .attr("class", "line")
      .attr("d", line);
});


</script>
  
  
  </body>
</html>



















